package com.ly.nethub.config

sealed interface ConnectStatus {
    val code: Int
    val msg: String

    data class Unconnected(
        override val code: Int = CODE_UNCONNECTED,
        override val msg: String = NetHubErrorMsg[CODE_UNCONNECTED]
    ) : ConnectStatus

    data class Connecting(
        override val code: Int = CODE_CONNECTING,
        override val msg: String = NetHubErrorMsg[CODE_CONNECTING]
    ) : ConnectStatus

    data class Connected(
        override val code: Int = CODE_CONNECTED,
        override val msg: String = NetHubErrorMsg[CODE_CONNECTED]
    ) : ConnectStatus

    sealed interface ConnectFailed : ConnectStatus {
        data class Failed(
            override val code: Int = CODE_CONNECT_FAILED,
            override val msg: String = NetHubErrorMsg[CODE_CONNECT_FAILED]
        ) : ConnectFailed

        data class Closed(
            override val code: Int = CODE_CONNECT_FAILED_CLOSED,
            override val msg: String = NetHubErrorMsg[CODE_CONNECT_FAILED_CLOSED]
        ) : ConnectFailed

        data class AddressListEmpty(
            override val code: Int = CODE_CONNECT_FAILED_SERVER_LIST_EMPTY,
            override val msg: String = NetHubErrorMsg[CODE_CONNECT_FAILED_SERVER_LIST_EMPTY]
        ) : ConnectFailed


        data class ServerIllegitimate(
            override val code: Int = CODE_CONNECT_FAILED_SERVER_ILLEGITIMATE,
            override val msg: String = NetHubErrorMsg[CODE_CONNECT_FAILED_SERVER_ILLEGITIMATE]
        ) : ConnectFailed

        data class NetworkUnavailable(
            override val code: Int = CODE_CONNECT_FAILED_NETWORK_UNAVAILABLE,
            override val msg: String = NetHubErrorMsg[CODE_CONNECT_FAILED_NETWORK_UNAVAILABLE]
        ) : ConnectFailed
    }

    companion object {
        val unconnected get() = Unconnected()

        val connecting get() = Connecting()

        val connected get() = Connected()

        val failed get() = ConnectFailed.Failed()

        val closed get() = ConnectFailed.Closed()

        val addressListEmpty get() = ConnectFailed.AddressListEmpty()

        val serverIllegitimate get() = ConnectFailed.ServerIllegitimate()

        val networkUnavailable get() = ConnectFailed.NetworkUnavailable()

    }
}

